<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<jsp:include page="/common.jsp" />
    <base href="<%=basePath%>">
    <%@ include file="/taglibs.jsp"%>
    <title>上传</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <script type="text/javascript">
    	var middleAreaId='<%=request.getParameter("middleAreaId")%>' ;
    	
    	var path='<%=path%>';
    	var combo_first_classify = new Ext.form.ComboBox({
			    typeAhead: true,
			    triggerAction: 'all',
			    lazyRender:true,
			    editable:false,
			    mode: 'local',
			    fieldLabel:'一级分类',
			    emptyText:'请选择',
			    store: new Ext.data.ArrayStore({
			        id: 0,
			        fields: [
			            'classId',
			            'className'
			        ]
			    }),
			    valueField: 'classId',
			    displayField: 'className'
			});
			var combo_second_classify = new Ext.form.ComboBox({
			    typeAhead: true,
			    triggerAction: 'all',
			    lazyRender:true,
			    editable:false,
			    mode: 'local',
			    fieldLabel:'二级分类',
			    emptyText:'请选择',
			    store: new Ext.data.ArrayStore({
			        id: 0,
			        fields: [
			            'classId',
			            'displayText'
			        ]
			    }),
			    valueField: 'classId',
			    displayField: 'displayText'
			});
			var combo_company = new Ext.form.ComboBox({
			    typeAhead: true,
			    triggerAction: 'all',
			    lazyRender:true,
			    editable:false,
			    mode: 'local',
			    fieldLabel:'商家',
			    emptyText:'请选择',
			    id:'companyId',
			    store: new Ext.data.ArrayStore({
			        id: 0,
			        fields: [
			            'classId',
			            'className'
			        ]
			    }),
			    valueField: 'classId',
			    displayField: 'className'
			});
    	Ext.onReady(function(){
			var form_classify=new Ext.form.FormPanel({
				renderTo:'firstClassify',
				labelWidth:60,
				border:false,
				items:[combo_first_classify,combo_second_classify,combo_company]
			})
    	});
    	//返回所有一级分类的。。。。列表
    	Ext.Ajax.request({
    		url:path+'/classify/getAllFirstClassArray.do',
    		success:function(str){
    			var data = Ext.util.JSON.decode(str.responseText);
    			combo_first_classify.store.loadData(data);
    			combo_first_classify.on("select",function(combo,rec,index){
    				getSecondClsByFid(rec.data.classId);
    			})
    		}
    	});
    	function getSecondClsByFid(firstClassId){
    		Ext.Ajax.request({
    		url:path+'/classify/getAllSecondClassArray.do?firstClassId='+firstClassId,
    		success:function(str){
    			var data = Ext.util.JSON.decode(str.responseText);
    			combo_second_classify.store.loadData(data);
    			combo_second_classify.on("select",function(combo,rec,index){
    					getCompanyById(rec.data.classId);
	    			})
	    		}
	    	});
    	};
    	function getCompanyById(secondClassId){
    		Ext.Ajax.request({
    		url:path+'/classify/getAllCompanyArray.do?secondClassId='+secondClassId,
	    		success:function(str){
	    			var data = Ext.util.JSON.decode(str.responseText);
	    			combo_company.store.loadData(data);
	    			combo_company.on("select",function(combo,rec,index){
	    			})
	    		}
	    	});
    	};
    	
  		function fileUpload(){
  			var filename=document.uploadform.fileName.value;
  			var companyId=combo_company.getValue();
  			if(companyId==''){
  				alert('请选择关联的商家');
  				return;
  			}
  			if(filename==''){
  				alert('选择文件');
  				return;
  			}
  			if(document.getElementById('picName').value==null||document.getElementById('picName').value==''){
  				alert("输入图片名称");
  				return;
  			}
  			var types=filename.split('.');
  			var type=types[types.length-1]
  			if(type!='jpg' && type!='JPG' && type!='png' && type!='PNG' && type!='GIF' && type!='gif'){
  				alert('请选择图片');
  				return;
  			}
  			var url="<%=path%>/picture/uploadMiddleAreaPic.do?fileName="+filename+"&middleAreaId="+middleAreaId+"&companyId="+companyId;
  			var form=document.uploadform;
  			form.action=url;
  			form.submit();
  		}
  		function winclose(){
  			window.close();
  		}
  	</script>
  	<div >
  		<div id="firstClassify"></div>
  		<form action="" name="uploadform" method="post" enctype="multipart/form-data" >
  			图片名称：<input type='text' name='picName' id='picName'>
  			
  			<s:file name="fileName"/>
  			<input type='button' value="上传" name="upload" onclick="fileUpload();"/>
  			<input type='button' value="关闭" name="close" onclick="winclose();"/>
  		</form>
  	</div>
  	<style>
		body {
		margin: 0;
		padding: 0 0 12px 0;
		font-size: 12px;
		line-height: 22px;
		font-family: "宋体", "Arial Narrow";
		background: #fff;
	}
  </body>
</html>
